import './video.js'
import './lineHeight.js'

const titleTips = {
  'ql-bold': '加粗',
  'ql-color': '颜色',
  'ql-font': '字体',
  'ql-code': '插入代码',
  'ql-italic': '斜体',
  'ql-link': '添加链接',
  'ql-background': '背景颜色',
  'ql-size': '字体大小',
  'ql-strike': '删除线',
  'ql-script': '上标/下标',
  'ql-underline': '下划线',
  'ql-blockquote': '引用',
  'ql-header': '标题',
  'ql-indent': '缩进',
  'ql-list': '列表',
  'ql-align': '文本对齐',
  'ql-direction': '文本方向',
  'ql-code-block': '代码块',
  'ql-formula': '公式',
  'ql-image': '图片',
  'ql-video': '视频',
  'ql-clean': '清除字体样式',
  'ql-upload': '文件'
}
const resizeVal = [
  '12px',
  '14px',
  '16px',
  '18px',
  '20px',
  '22px',
  '24px',
  '26px',
  '28px',
  '30px',
  '32px',
  '34px',
  '36px',
  '38px',
  '40px',
  '42px',
  '44px',
  '46px',
  '48px',
  '50px',
  '52px',
  '54px'
]

function getTitleTip(name, value) {
  let tip = ''
  if (name === 'ql-script') {
    value === 'sub' ? (tip = '下标') : (tip = '上标')
  } else if (name === 'ql-indent') {
    value === '+1' ? (tip = '向右缩进') : (tip = '向左缩进')
  } else {
    tip = titleTips[name]
  }
  return tip
}

function getToolBarList(type) {
  const barList = {
    toolbarList: [
      ['bold', 'italic', 'underline', 'strike'],
      [{ color: [] }, { background: [] }],
      [{ align: [] }],
      [{ header: 1 }, { header: 2 }],
      [{ list: 'ordered' }, { list: 'bullet' }],
      [{ indent: '-1' }, { indent: '+1' }],
      [{ size: ['small', false, 'large', 'huge'] }],
      [{ lineheight: ['initial', '1', '1.5', '1.75', '2', '3', '4', '5'] }],
      ['clean'],
      ['image', 'video', 'link']
    ],
    toolbarList2: [
      ['bold', 'italic', 'underline', 'strike'],
      [{ color: [] }, { background: [] }],
      [{ align: [] }],
      [{ header: 1 }, { header: 2 }],
      ['clean']
    ],
    toolbarList3: [
      ['bold', 'italic', 'underline', 'strike'],
      [{ color: [] }, { background: [] }],
      // [{ size: ['small', false, 'large', 'huge'] }],
      [{ resize: resizeVal }],
      [{ lineheight: ['initial', '1', '1.5', '1.75', '2', '3', '4', '5', '6'] }]
    ],
    toolbarList4: [
      ['bold', 'italic', 'underline', 'strike'],
      [{ resize: resizeVal }],
      [{ lineheight: ['initial', '1', '1.5', '1.75', '2', '3', '4', '5', '6'] }]
    ]
  }
  if (!type) return barList.toolbarList

  return barList[type] ? barList[type] : barList.toolbarList2
}

function options(handlers, type, maxLength) {
  console.log(type, maxLength, getToolBarList(type), 'dddddddd')
  return {
    theme: 'snow',
    modules: {
      toolbar: {
        container: getToolBarList(type),
        handlers
      }
    },
    placeholder: '请输入正文 ...',
    maxLength: maxLength
  }
}

export default {
  getTitleTip,
  options
}
